package com.xiaobai.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义spring mvc的相关配置
 *
 * @author bailiang 19044171
 * @date 2019/12/19
 */
@Configuration
@Slf4j
public class SpringMvcConfiguration implements WebMvcConfigurer {

    /**
     * 配置文件上传处理器
     */
    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");
        resolver.setResolveLazily(true);// resolveLazily属性启用是为了推迟文件解析，以在UploadAction中捕获文件大小异常
        resolver.setMaxUploadSizePerFile(30L * 1024L * 1024L);// 单个文件上传的大小 30M 50*1024*1024
        resolver.setMaxUploadSize(50L * 1024L * 1024L);//上传文件大小 50M 50*1024*1024
        resolver.setMaxInMemorySize(4096);
        return resolver;
    }
}